package com.example.myapplication.tack_22.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.tack_22.data.AllRoutesData;
import com.example.myapplication.tack_22.data.MetroData;

import java.util.List;

public class MetroAdapter extends RecyclerView.Adapter<MetroAdapter.My> {
    private List<MetroData.DataDTO.MetroStepListDTO> list;
    private Context context;
    private View view;
    private String RunStationsName;
    public MetroAdapter(List<MetroData.DataDTO.MetroStepListDTO> list, Context context,String RunStationsName) {
        this.list = list;
        this.context = context;
        this.RunStationsName = RunStationsName;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.tack_22_lu_xian,null);

        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        if(!TextUtils.isEmpty(list.get(position).getName())){
            holder.name.setTextColor(Color.BLACK);
            holder.name.setText(list.get(position).getName());
        }
        if(RunStationsName.equals(list.get(position).getName())){
            holder.name.setTextColor(Color.RED);
        }


    }

    @Override
    public int getItemCount() {
        return list != null?list.size():0;
    }

    public class My extends RecyclerView.ViewHolder{
        private TextView name;

        public My(@NonNull View itemView) {
            super(itemView);
            name = view.findViewById(R.id.name);
        }
    }
}
